package com.lcm.jnode.controller;

import java.util.List;

import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.lcm.jnode.interceptor.SidebarInterceptor;
import com.lcm.jnode.model.Blog;
import com.lcm.jnode.model.BlogTag;
import com.lcm.jnode.utils.DateUtils;

/**
 * 博文详情
 * @author L.cm
 * @date 2013-5-14 下午5:08:12
 */
public class BlogController extends Controller{
    
    @Before(SidebarInterceptor.class)
	public void index() {
    	int id = getParaToInt(0, 1);
    	// 读写分离
	    Blog blog = Blog.dao.findFallById(id);
	    Blog db_blog = Blog.dao.findById(id);
	    db_blog.set(Blog.VIEW_COUNT, db_blog.getInt(Blog.VIEW_COUNT) + 1).update();
	    // 获取标签
	    // TODO 标签完善
	    //List<BlogTag> blogTagsList = BlogTag.dao.findBlogTagList(blog.getInt(Blog.ID)); 
	    setAttr("blog", blog);
	    //setAttr("blogTagsList", blogTagsList);
	    setAttr("title", blog.getStr(Blog.TITLE));
	    setAttr("typeName", Blog.TYPE_NAME[blog.getInt(Blog.BLOG_TYPE)]);
	    setAttr("typeUrl", Blog.TYPE_URL[blog.getInt(Blog.BLOG_TYPE)]);
	    render("blog");
	}
}
